package com.aat.dxfy.redis.util.redis;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class PropUtil {
  private static final Logger LOGGER = LoggerFactory.getLogger(PropUtil.class);
  private static final String FILENAME = "search-application-redis.properties";
  private static Properties prop = new Properties();

  static {
    ClassLoader loader = PropUtil.class.getClassLoader();
    InputStream in = null;
    try {
      in = loader.getResourceAsStream(FILENAME);
      prop.load(in);
    } catch (IOException e11) {
      LOGGER.error("Load " + FILENAME + " failed!", e11);
    } finally {
      if (in != null) {
        try {
          in.close();
        } catch (IOException e22) { 
          //
        }
      }
    }
  }

  private PropUtil() {
  }

  /**
   * 
   * @param key.
   * @param defultVal.
   * @return str.
   */
  public static String getStr(String key, String defultVal) {
    String val = prop.getProperty(key);
    if (val == null || val.length() == 0) {
      val = defultVal;
    }
    return val;
  }
  
  /**
   * 
   * @param key.
   * @param defultVal.
   * @return str.
   */
  public static String getProperty(String key, String defultVal) {
    String val = prop.getProperty(key);
    if (val == null || val.length() == 0) {
      val = defultVal;
    }
    return val;
  }

  /**
   * 
   * @param key.
   * @param defultVal.
   * @return str.
   */
  public static Integer getInt(String key, Integer defultVal) {
    String val = prop.getProperty(key);
    Integer intval = defultVal;
    if (val != null && val.length() > 0) {
      intval = Integer.parseInt(val);
    }
    return intval;
  }

}
